import java.util.List;

@RestController
@RequestMapping("/user")
public class UserColltroller extends BaseController{

    @Autowired
    private UserService userService;

    @GetMapping("/{userId}")
    public ResponseResult<List<UserVo>> readBedByRoomId( @PathVariable("userId") Long userId) {
        List<User> users = userService.getUsersById(userId);
        return success(users);
    }

    //新增
    @PostMapping("/create")
    public ResponseResult cerateUser(@RequestBody UserDto userDto){
        userService.addBad(userDto);
        return success();
    }

    //根据id查询床位
    @GetMapping("/read/{id}")
    public ResponseResult<UserVo> readBed(@PathVariable("id") Long id){

        return success(userService.getById(id));
    }

    //修改信息
    @PutMapping("/update")
    public ResponseResult updateUser(@RequestBody UserDto userDto){
        userService.updateBed(userDto);
        return success();
    }

    //删除信息
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        userService.delUser(id);
        return success();
    }
}
